<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>随访档案详情</title>
  <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
  <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
  </script>
  <!-- <link rel="stylesheet" href="../../css/public.css" media="all"> -->
</head>
<style>
  .layui-form-label {
    width: 150px !important;
    text-align: center !important;
  }

  .layui-input-block {
    margin-left: 150px !important;
  }
</style>

<body>
  <div class="layuimini-container">
    <div class="layuimini-main">

      <!-- <fieldset class="table-search-fieldset"> -->
      <div style="margin: 10px 10px 10px 10px">
        <div class="layui-form layui-form-pane" action="">
          <div class="layui-form-item">
            <fieldset class="layui-elem-field layui-field-title">
              <legend><a class="layui-form-mid layui-word-aux" style="font-size: 15px;" name="color-design">基本信息</a>
              </legend>
            </fieldset>
            <div class="layui-form-item">
              <label class="layui-form-label">id号</label>
              <div class="layui-input-block">
                <input type="text" id="id" name="id" autocomplete="off" class="layui-input" disabled>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">患者姓名</label>
                <div class="layui-input-block">
                  <input type="text" id="realName" name="realName" autocomplete="off"  class="layui-input dis-base" disabled>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">患者手机号</label>
                <div class="layui-input-block">
                  <input type="text" id="phoneNum" name="phoneNum" autocomplete="off" disabled class="layui-input dis-base">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">家属手机号</label>
                <div class="layui-input-block">
                  <input type="text" id="dependentNum" name="dependentNum" autocomplete="off" disabled
                    class="layui-input dis-base">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">身份证号</label>
                <div class="layui-input-block">
                  <input type="text" id="idNumber" name="idNumber" autocomplete="off" disabled class="layui-input dis-base">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">建档医生</label>
                <div class="layui-input-block">
                  <input type="text" id="doctorName" name="doctorName" autocomplete="off" disabled class="layui-input">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">随访阶段</label>
                <div class="layui-input-block">
                  <input type="text" id="followPace" name="followPace" autocomplete="off" disabled class="layui-input">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">下次随访时间</label>
                <div class="layui-input-block">
                  <input type="text" id="nextTime" name="nextTime" autocomplete="off" autocomplete="off"
                    class="layui-input date-time dis-base" placeholder="点击以选择" lay-verify="datetime" disabled>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">已经随访次数</label>
                <div class="layui-input-block">
                  <input type="text" id="followCounts" name="followCounts" autocomplete="off" autocomplete="off"
                    class="layui-input dis-base" value="0" disabled>
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">植入原因</label>
              <div class="layui-input-block" >
                <input type="radio" name="reason" value="病窦" title="病窦" lay-filter="reason" disabled class="dis-base">
                <input type="radio" name="reason" id="reason_1" value="房室传导阻滞一度" title="房室传导阻滞x级" lay-filter="reason" disabled class="dis-base">
                <input type="radio" name="reason" value="房颤伴长RR间期" title="房颤伴长RR间期" lay-filter="reason" disabled class="dis-base">
                <input type="radio" name="reason" value="晕厥" title="晕厥" lay-filter="reason" disabled class="dis-base">
                <input type="radio" name="reason" id="reason_2" value="心衰1级" title="心衰x级" lay-filter="reason"disabled class="dis-base">
                <input type="radio" name="reason" value="心肌病" title="心肌病" lay-filter="reason"disabled class="dis-base">
                <input type="radio" name="reason" value="冠心病" title="冠心病" lay-filter="reason"disabled class="dis-base">
                <input type="radio" name="reason" value="心脏骤停" title="心脏骤停" lay-filter="reason"disabled class="dis-base">
                <input type="radio" name="reason" id="reason_3" value="其他" title="其他" lay-filter="reason"disabled class="dis-base">
                <div id="reason_more_1" class="layui-hide">
                  <select lay-filter="reason_more_1"disabled class="dis-base">
                    <option value="一度">一度</option>
                    <option value="二度一型AVB">二度一型AVB</option>
                    <option value="二度二型AVB">二度二型AVB</option>
                    <option value="三度">三度</option>
                  </select>
                </div>
                <div id="reason_more_2" class="layui-hide">
                  <select lay-filter="reason_more_1"disabled class="dis-base">
                    <option value="1级">1级</option>
                    <option value="2级">2级</option>
                    <option value="3级">3级</option>
                    <option value="4级">4级</option>
                  </select>
                </div>
                <input type="text" id="reason_more_3" autocomplete="off" autocomplete="off"
                  class="layui-input layui-hide dis-base" placeholder="请输入详细原因" disabled>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">详细介绍</label>
              <div class="layui-input-block">
                <textarea type="text" id="introduce" name="introduce" autocomplete="off" autocomplete="off"
                  class="layui-input dis-base" style="height:80px;" disabled></textarea>
              </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title">
              <legend><a class="layui-form-mid layui-word-aux" style="font-size: 15px;" name="color-design">起搏器选择</a>
              </legend>
            </fieldset>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">起搏器Id</label>
                <div class="layui-input-block">
                  <select name="pacemakerId" id="pacemakerId" lay-search disabled class="dis-base">
                  </select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">是否起搏器依赖</label>
                <div class="layui-input-block">
                  <select name="pacemakerDepend"disabled class="dis-base">
                    <option value="1">是</option>
                    <option value="2">否</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">起搏器名称</label>
                <div class="layui-input-block">
                  <input type="text" id="pacemakerCompanyName"  autocomplete="off" disabled
                    class="layui-input">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">起搏器型号</label>
                <div class="layui-input-block">
                  <input type="text" id="pacemakerModelNumber" autocomplete="off" disabled
                    class="layui-input">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">起搏器序列号</label>
                <div class="layui-input-block">
                  <input type="text" id="pacemakerProductNumber" autocomplete="off"
                    disabled class="layui-input">
                </div>
              </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title">
              <legend><a class="layui-form-mid layui-word-aux" style="font-size: 15px;" name="color-design">手术信息</a>
              </legend>
            </fieldset>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">植入时间</label>
                <div class="layui-input-block">
                  <input type="text" id="createTime" name="createTime" autocomplete="off" autocomplete="off"
                    class="layui-input date-time dis-base" disabled placeholder="点击以选择" lay-verify="datetime">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">手术者</label>
                <div class="layui-input-block">
                  <select name="surgeon" id="surgeon" lay-search disabled class="dis-base">
                  </select>
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">植入医院</label>
              <div class="layui-input-block">
                <input type="text" id="hospital" name="hospital" autocomplete="off" autocomplete="off"
                  placeholder="中南医院" class="layui-input" disabled class="dis-base">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">手术过程</label>
              <div class="layui-input-block">
                <textarea type="text" id="surgicalDetail" name="surgicalDetail" autocomplete="off" autocomplete="off"
                  class="layui-input dis-base" disabled style="height:80px;"></textarea>
              </div>
            </div>

            <div style="position: absolute; right: 17px;">
              <button id="change_base" type="button" class="layui-btn" style="margin-right: 0;" 
                lay-filter="change_base" onclick="changeBase()">信息修改</button>
            </div>
            <div style="position: absolute; right: 17px;">
              <button id="save_base" type="button" class="layui-btn" style="margin-right: 0;" lay-submit
                lay-filter="save_base">保存提交</button>
            </div>
            <fieldset class="layui-elem-field layui-field-title" style="margin-top:45px">
              <legend><a class="layui-form-mid layui-word-aux" style="font-size: 15px;" name="color-design">电极信息</a>
              </legend>
            </fieldset>
            <div class="layui-form-item" style="height: 8%;">
              <label class="layui-form-label">植入位置</label>
              <div class="layui-input-block" >
                <input type="checkbox" name="wirePosition" value="1" title="右心房" lay-skin="primary" id = "wirePosition_raIn"
                  lay-filter="wirePosition" disabled class = "dis-wire">
                <input type="checkbox" name="wirePosition" value="2" title="右心室" lay-skin="primary" id = "wirePosition_rvIn"
                  lay-filter="wirePosition" disabled class = "dis-wire">
                <input type="checkbox" name="wirePosition" value="3" title="左心室" lay-skin="primary" id = "wirePosition_lvIn"
                  lay-filter="wirePosition" disabled class = "dis-wire">
              </div>
            </div>
            <fieldset class="layui-elem-field layui-hide" id="wirePosition_1">
              <legend style="font-size: 15px;color: gray;">右心房</legend>
              <div class="layui-field-box">
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">导线型号</label>
                    <div class="layui-input-inline">
                      <select name="wireId_1" id="wireId_1" lay-search disabled class="dis-wire">
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">阈值(V)/脉宽(ms)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="tdpw_1" id="tdpw_1" autocomplete="off" class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">P/R波(mv)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="prwave_1" id="prwave_1" autocomplete="off" class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">起搏阻抗(Ω)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="pacingImpedance_1" id="pacingImpedance_1" autocomplete="off"
                        class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">除颤能量(J)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="defibrillationEnergy_1" id="defibrillationEnergy_1" autocomplete="off"
                        class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">除颤阻抗(Ω)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="defibrillationImpedance_1" id="defibrillationImpedance_1"
                        autocomplete="off" class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                </div>
              </div>
            </fieldset>
            <fieldset class="layui-elem-field  layui-hide" id="wirePosition_2">
              <legend style="font-size: 15px;color: gray;">右心室</legend>
              <div class="layui-field-box">
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">导线型号</label>
                    <div class="layui-input-inline">
                      <select name="wireId_2" id="wireId_2" lay-search disabled class="dis-wire">
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">阈值(V)/脉宽(ms)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="tdpw_2" id="tdpw_2" autocomplete="off" class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">P/R波(mv)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="prwave_2" id="prwave_2" autocomplete="off" class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">起搏阻抗(Ω)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="pacingImpedance_2" id="pacingImpedance_2" autocomplete="off"
                        class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">除颤能量(J)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="defibrillationEnergy_2" id="defibrillationEnergy_2" autocomplete="off"
                        class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">除颤阻抗(Ω)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="defibrillationImpedance_2" id="defibrillationImpedance_2"
                        autocomplete="off" class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                </div>
              </div>
            </fieldset>
            <fieldset class="layui-elem-field  layui-hide" id="wirePosition_3">
              <legend style="font-size: 15px;color: gray;">左心室</legend>
              <div class="layui-field-box">
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">导线型号</label>
                    <div class="layui-input-inline">
                      <select name="wireId_3" id="wireId_3" lay-search disabled class="dis-wire" >
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">阈值(V)/脉宽(ms)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="tdpw_3" id="tdpw_3" autocomplete="off" class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">P/R波(mv)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="prwave_3" id="prwave_3" autocomplete="off" class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">起搏阻抗(Ω)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="pacingImpedance_3" id="pacingImpedance_3" autocomplete="off"
                        class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">除颤能量(J)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="defibrillationEnergy_3" id="defibrillationEnergy_3" autocomplete="off"
                        class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">除颤阻抗(Ω)</label>
                    <div class="layui-input-inline">
                      <input type="text" name="defibrillationImpedance_3" id="defibrillationImpedance_3"
                        autocomplete="off" class="layui-input dis-wire" disabled>
                    </div>
                  </div>
                </div>
              </div>
            </fieldset>
            
            <div style="position: absolute; right: 17px;">
              <button id="change_wire" type="button" class="layui-btn" style="margin-right: 0;" lay-submit
                lay-filter="change_wire" onclick="changeWire()">信息修改</button>
            </div>
            <div style="position: absolute; right: 17px;">
              <button id="save_wire" type="button" class="layui-btn" style="margin-right: 0;" lay-submit
                lay-filter="save_wire">保存提交</button>
            </div>
            <!-- <div style="position: absolute; right: 17px;">
              <button id="closebtn" type="button" class="layui-btn" style="margin-right: 0;" lay-submit
                lay-filter="saveBtn">保存提交</button>
            </div> -->
          </div>
        </div>
      </div>
      <!-- </fieldset> -->
    </div>
  </div>
  <script>
    /**
     * 
     * 初始变量储存地
     * 
     */
    var rlIn = {"raIn":false,"rvIn":false,"lvIn":false}
    var data_origin 
    /**
     * 
     * Date 格式化工具     
     * 
     */
    Date.prototype.format = function(fmt) { 
      var o = { 
          "M+" : this.getMonth()+1,                 //月份 
          "d+" : this.getDate(),                    //日 
          "h+" : this.getHours(),                   //小时 
          "m+" : this.getMinutes(),                 //分 
          "s+" : this.getSeconds(),                 //秒 
          "q+" : Math.floor((this.getMonth()+3)/3), //季度 
          "S"  : this.getMilliseconds()             //毫秒 
      }; 
      if(/(y+)/.test(fmt)) {
              fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
      }
      for(var k in o) {
          if(new RegExp("("+ k +")").test(fmt)){
              fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
          }
      }
      return fmt; 
    }        
    /**
     * 
     * 初始化下拉栏的表单
     * 
     * 
    */
    function setList() {
      /**
       * 
       * 初始化医生下拉栏
       * 
       * */
      layui.$.ajax({
        url: `${url_basic}/doctor/all?onlySelect=id,name`,
        type: "POST",
        contentType: 'application/json',
        success: function (data, textStatus) {
          if (data.code == 0) {
            document.getElementById("surgeon").innerHTML = "";
            for (let index = 0; index < data.data.length; index++) {
              const element = data.data[index];
              var newOption = document.createElement("option");
              newOption.text = element.name;
              newOption.value = element.id;
              document.getElementById("surgeon").add(newOption);
            }
            layui.form.render("select");
            return true;
          }
          else {
            layer.msg('失败，原因：' + data.msg);
            return false;
          }
        },
        error: function (xhr, errorText, errorType) {
          layer.msg('更新清单失败（与服务器连接失败）');
        },
        dataType: "json"
      })

      /**
       * 
       * 初始化起搏器下拉栏
       * 
       * */
      layui.$.ajax({
        url: `${url_basic}/pacemaker/all?onlySelect=id,name`,
        type: "POST",
        contentType: 'application/json',
        success: function (data, textStatus) {
          if (data.code == 0) {
            document.getElementById("pacemakerId").innerHTML = "";
            for (let index = 0; index < data.data.length; index++) {
              const element = data.data[index];
              var newOption = document.createElement("option");
              newOption.text = element.name;
              newOption.value = element.id;
              document.getElementById("pacemakerId").add(newOption);
            }
            layui.form.render("select");
            return true;
          }
          else {
            layer.msg('失败，原因：' + data.msg);
            return false;
          }
        },
        error: function (xhr, errorText, errorType) {
          layer.msg('更新清单失败（与服务器连接失败）');
        },
        dataType: "json"
      })
      /**
       * 
       * 初始化导线下拉栏
       * 
       * */
      var wireIds = ['wireId_1', 'wireId_2', 'wireId_3']
      layui.$.ajax({
        url: `${url_basic}/wire/all?onlySelect=id,modelNumber`,
        type: "POST",
        contentType: 'application/json',
        success: function (data, textStatus) {
          if (data.code == 0) {
            for (key in wireIds) {
              obj = document.getElementById(wireIds[key])
              obj.innerHTML = "";
              for (let index = 0; index < data.data.length; index++) {
                const element = data.data[index];
                var newOption = document.createElement("option");
                newOption.text = element.modelNumber;
                newOption.value = element.id;
                obj.add(newOption);
              }
            }
            layui.form.render("select");
            return true;
          }
          else {
            layer.msg('失败，原因：' + data.msg);
            return false;
          }
        },
        error: function (xhr, errorText, errorType) {
          layer.msg('更新清单失败（与服务器连接失败）');
        },
        dataType: "json"
      })
    }

    var method = "新增" // 也可能是"修改"，由传参决定
    var data_wire_id = {"raIn":0,"rvIn":0,"lvIn":0}
    /**
     * 
     * 植入起搏器原因切换
     * 
     * */
    function cleanSingleChoice() {
      var itmhide = ['reason_more_1', 'reason_more_2', 'reason_more_3']
      for (var key in itmhide) {
        if (!document.getElementById(itmhide[key]).classList.contains('layui-hide')) {
          document.getElementById(itmhide[key]).classList.add('layui-hide');
        }
      }
    }

    /**
     * 
     * 对基础进行修改
     * 
     */
    function changeBase(){
      $(".dis-base").attr("disabled",false)
      layui.form.render()
      $("#change_base").hide(200)
      $("#save_base").show(200)
    }
    /**
     * 
     * 对电极信息进行修改
     * 
     */
     function changeWire(){
      $(".dis-wire").attr("disabled",false)
      layui.form.render()
      $("#change_wire").hide(200)
      $("#save_wire").show(200)
    }

    /**
     * 
     * layui核心设置
     * 
     * */
    layui.use(['laydate', 'form', 'jquery', 'table'], function () {
      var laydate = layui.laydate,
        form = layui.form,
        table = layui.table,
        $ = layui.$;

      $("#save_base").hide()
      $("#save_wire").hide()
      /**
       * 
       * 设置layui时间选择器
       * 
       * */
      var datatime_elems = document.getElementsByClassName("date-time")
      for (var i = 0; i < datatime_elems.length; i++) {
        laydate.render({
          elem: datatime_elems[i]
          , type: 'datetime'
        });
      }
      /**
       * 
       * 设置layui选项卡
       * 
       * */
      setList();

      /**
       * 
       * 设置layui输入框值校验
       * 
       * */
      form.verify({
      });

      /**
       * 
       * 植入起搏器的位置的切换
       * 
       * */
      form.on('checkbox(wirePosition)', function (data) {
        if (data.elem.checked) {
          document.getElementById('wirePosition_' + data.value).classList.remove('layui-hide');
        } else {
          document.getElementById('wirePosition_' + data.value).classList.add('layui-hide');
        }
      });

      /**
       * 
       * 植入起搏器的原因的切换
       * 
       * */
      form.on('radio(reason)', function (data) {
        cleanSingleChoice()
        if (data.value.substring(0, 2) == '房室') {
          document.getElementById('reason_more_1').classList.remove('layui-hide');
        } else if (data.value.substring(0, 2) == '心衰') {
          document.getElementById('reason_more_2').classList.remove('layui-hide');
        } else if (data.value.substring(0, 2) == '其他') {
          document.getElementById('reason_more_3').classList.remove('layui-hide');
        }
      });
      /**
       * 
       * 拼接复杂原因
       * 
       * */
      form.on('select(reason_more_1)', function (data) {
        document.getElementById('reason_1').value = "房室传导阻滞" + data.value;
      });
      form.on('select(reason_more_2)', function (data) {
        document.getElementById('reason_2').value = "心衰" + data.value;
      });

      //监听提交
      var content_1 = ['position_1', 'wireId_1', 'tdpw_1', 'prwave_1', 'pacingImpedance_1', 'defibrillationEnergy_1', 'defibrillationImpedance_1']
      var content_2 = ['position_2', 'wireId_2', 'tdpw_2', 'prwave_2', 'pacingImpedance_2', 'defibrillationEnergy_2', 'defibrillationImpedance_2']
      var content_3 = ['position_3', 'wireId_3', 'tdpw_3', 'prwave_3', 'pacingImpedance_3', 'defibrillationEnergy_3', 'defibrillationImpedance_3']
      form.on('submit(save_base)', function (data) {
        /**
         * 
         * 删除为空项
         * 
         * */
        for (var key in data.field) {
          if (data.field[key] === '')
            delete data.field[key]
        }
        /**
         * 
         * 为电极位置的发送准备数据
         * 
         * */
        for (var key in data.field) {
          if (content_1.includes(key)||content_2.includes(key)||content_3.includes(key)) {
            delete data.field[key]
          }
        }
        $.each(rlIn,function(key,val){
          data.field[key] = val
        })
        data.field["doctorId"] = 53
        /**
         * 
         * 校验发送数据
         * 
         * */
        // //console.log('基础信息修改，发送数据如下：')
        // //console.log(JSON.stringify(data.field))

        /**
         * 
         * 发送区
         * 
         * */
        $.ajax({
          url: `${url_basic}/medicalRecords/update`,
          type: "POST",
          data: JSON.stringify(data.field),
          contentType: 'application/json',
          success: function (data, textStatus) {
            if (data.code == 0) {
              layer.msg('基本信息修改成功', { time: 0.5 * 1000 }, function () { });
              var iframeIndex = parent.layer.getFrameIndex(window.name);
              parent.layer.close(iframeIndex);
              return true;
            }
            else {
              layer.msg('失败，原因：' + data.msg);
              return false;
            }
          },
          error: function (xhr, errorText, errorType) {
            layer.msg('修改失败（与服务器连接失败）');
          },
          dataType: "json"
        })
        return false;

      });

      form.on('submit(save_wire)',function(data){
        var data_send = data_origin
        var data_more = ['pacemakerCompanyName','pacemakerModelNumber','pacemakerProductNumber','pacemakerName','doctorName','doctorWorkNumber','surgeonName','surgeonWorkNumber']
        for (var key in data_send) {
          if (data_send[key] === '')
            delete data_send[key]
        }
        for (var key in data.field) {
          if (data.field[key] === '')
            delete data.field[key]
        }
        for (var key in data_send) {
          if (data_more.includes(key)) {
            delete data_send[key]
          }
        }
        var data_in = {"raIn":{},"rvIn":{},"lvIn":{}};
        var data_tag = {"raIn":0,"rvIn":0,"lvIn":0}
        var data_position = {"raIn":1,"rvIn":2,"lvIn":3};

        for(var key in data.field){
          if(content_1.includes(key)){
            data_in["raIn"][key.slice(0,-2)] = data.field[key];
            data_tag["raIn"]++;
            delete data.field[key]
          }
          else if(content_2.includes(key)){
            data_in["rvIn"][key.slice(0,-2)] = data.field[key];
            data_tag["rvIn"]++
            delete data.field[key]
          }
          else if(content_3.includes(key)){
            data_in["lvIn"][key.slice(0,-2)] = data.field[key];
            data_tag["lvIn"]++;
            delete data.field[key]
          }
        }
        var heart = {"raIn":'右心房',"rvIn":'右心室',"lvIn":'左心室'}
        $.each(data_tag,function(key,val){
          if(data_tag[key]<6 && $(`#wirePosition_${key}`).prop("checked")){
            layer.msg('请输入完整的'+ heart[key] +'信息');
            return false;
          }
        })
        $.each(data_tag,function(key,val){
          if(val == 6 && $(`#wirePosition_${key}`).prop("checked")){
            data_send[key] = true;
            data_in[key]["recordId"] = data_origin.id;
            data_in[key]["position"] = data_position[key];
            if(rlIn[key]){
              data_in[key]["id"] = data_wire_id[key]
            }
            $.ajax({
              url: `${url_basic}/recordWire/${rlIn[key] ? 'update' : 'add'}`,
              type: "POST",
              data: JSON.stringify(data_in[key]),
              contentType: 'application/json',
              success: function (data, textStatus) {
                if (data.code == 0) {
                  layer.msg('成功', { time: 0.5 * 1000 }, function () {
                    // 关闭弹出层
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                  });
                  return true;
                }
                else {
                  layer.msg('添加失败，原因：' + data.msg);
                  return false;
                }
              },
              error: function (xhr, errorText, errorType) {
                layer.msg('添加电极信息失败（与服务器连接失败）');
              },
              dataType: "json"
            })
          }else{
            if(rlIn[key]){
              $.ajax({
                url: urlfront + "/recordWire/delete",
                type: "POST",
                data: JSON.stringify([data_wire_id[key]]),
                contentType: 'application/json',
                success: function (data, textStatus) {
                    if (data.code == 0) {
                        layer.msg('多余条目删除成功', { time: 0.5 * 1000 }, function () { });
                    }
                    else {
                        layer.msg('删除失败，原因：' + data.msg);
                    }
                },
                error: function (xhr, errorText, errorType) {
                    layer.msg('删除失败（与服务器连接失败）');
                },
                complete: function () {
                    table.reload('currentTableId'); //只重载数据
                },
                dataType: "json"
            })
            }
            data_send[key] = false;
          }
        })

        $.ajax({
          url: `${url_basic}/medicalRecords/update`,
          type: "POST",
          data: JSON.stringify(data_send),
          contentType: 'application/json',
          success: function (data, textStatus) {
            if (data.code == 0) {
              layer.msg('基本信息修改成功', { time: 0.5 * 1000 }, function () { });
              return true;
            }
            else {
              layer.msg('失败，原因：' + data.msg);
              return false;
            }
          },
          error: function (xhr, errorText, errorType) {
            layer.msg('修改失败（与服务器连接失败）');
          },

          dataType: "json"
        })

      });

    });

    function setDataDetail(data, privilege) {
      data_origin = data
      data_origin['createTime'] = (new  Date(data.createTime)).format("yyyy-MM-dd hh:mm:ss")
      data_origin['nextTime'] = (new  Date(data.nextTime)).format("yyyy-MM-dd hh:mm:ss")
      this_privilege = privilege
        document.getElementById('id').value = data.id
        document.getElementById('realName').value = data.realName
        document.getElementById('phoneNum').value = data.phoneNum
        document.getElementById('dependentNum').value = data.dependentNum
        document.getElementById('idNumber').value = data.idNumber
        $("input[name = 'reason']").each(function () {
          if ($(this).val().slice(0, 2) == data.reason.slice(0, 2)) {
            $(this).attr("checked", true)
          }
        })
        switch (data.reason.slice(0, 2)) {
          case '房室':
            $("#reason_more_1").removeClass("layui-hide")
            $("#reason_1").val(data.reason)
            $(`option[value = ${data.reason.slice(6)}]`).attr("selected", true)
            break;
          case '心衰':
            $("#reason_more_2").removeClass("layui-hide")
            $("#reason_2").val(data.reason)
            $(`option[value = ${data.reason.slice(2)}]`).attr("selected", true)
            break;
          case '其他':
            $("#reason_more_3").removeClass("layui-hide")
            $("#reason_3").val(data.reason)
            $("#reason_more_3").val(data.reason.slice(3))
            break;
          default:
            break;
        }
        $("#introduce").text(data.introduce)
        $('#pacemakerId').val(data.pacemakerId)
        $('#pacemakerDepend').val(data.pacemakerDepend)
        document.getElementById('pacemakerModelNumber').value = data.pacemakerModelNumber
        document.getElementById('pacemakerProductNumber').value = data.pacemakerProductNumber
        document.getElementById('pacemakerCompanyName').value = data.pacemakerCompanyName
        var positionSet = [data.raIn, data.rvIn, data.lvIn]
        var position_data = {"1":"raIn","2":"rvIn","3":"lvIn"}
        $.each(rlIn,function(key,val){
          rlIn[key] = data[key]
        })
        $("input[name = 'wirePosition']").each(function () {
          if (positionSet[$(this).val() - 1]) {
            $(this).attr("checked", true)
            $(`#wirePosition_${$(this).val()}`).removeClass('layui-hide')
          }
        })
        var wiresearch = { "page": 1, "limit": 15, "recordId": data.id }
        $.ajax({
          url: `${url_basic}/recordWire/search`,
          type: "POST",
          data: JSON.stringify(wiresearch),
          contentType: 'application/json',
          success: function (data, textStatus) {
            if (data.code == 0) {
              $.each(data.data, function (key, val) {
                $.each(data.data[key], function (keyIn, valIn) {
                  if (keyIn != 'id' && keyIn != 'position') {
                    $(`#${keyIn}_${data.data[key]['position']}`).val(valIn)
                  }
                  if(keyIn == 'id'){
                    data_wire_id[position_data[data.data[key]["position"]]] = valIn
                  }
                })
              })
              return true;
            }
            else {
              layer.msg( '电极测试信息拉取失败，原因：' + data.msg);
              return false;
            }
          },
          error: function (xhr, errorText, errorType) {
            layer.msg('添加电极信息失败（与服务器连接失败）');
          },
          dataType: "json"
        })

        document.getElementById('doctorName').value = data.doctorName
        document.getElementById('createTime').value = (new  Date(data.createTime)).format("yyyy-MM-dd hh:mm:ss")
        document.getElementById('surgeon').value = data.surgeon
        document.getElementById('hospital').value = data.hospital
        document.getElementById('surgicalDetail').value = data.surgicalDetail
        document.getElementById('nextTime').value = (new  Date(data.nextTime)).format("yyyy-MM-dd hh:mm:ss")
        document.getElementById('followCounts').value = data.followCounts
        document.getElementById('followPace').value = data.followPace
        layui.use(['form'], function () { layui.form.render()});


    };
    function resetPassword() {
      document.getElementById('passwordBlock').style.visibility = "visible"
    };
    document.getElementById("reason_more_3").onchange = function (event) {
      document.getElementById('reason_3').value = "其他：" + event.target.value;
    };
  </script>
</body>

</html>